import { Component, OnInit } from "@angular/core";
import { WsService } from "../ws.service";
import * as WaveSurfer from "wavesurfer.js";
import { NzButtonModule } from 'ng-zorro-antd/button';
// declare var WaveSurfer: any;

@Component({
  selector: "app-mychat",
  templateUrl: "./mychat.component.html",
  styleUrls: ["./mychat.component.scss"],

})
export class MychatComponent implements OnInit {
  size='large';
  messageList = [];
  message = "Hello World!";
  wsUrl = "ws://107.174.192.132:2048/ws";
  error: any; // 异常信息
  completed = false; // 发送完成
  wavesurfer:any;
  constructor(private webSocketService: WsService) {}

  ngOnInit() {
    this.webSocketService.connect(this.wsUrl);
    this.webSocketService.messageSubject.subscribe(
      (data) => {
        // 否则添加到消息列表
        this.messageList.push(JSON.stringify(data));
      },
      (err) => (this.error = err),
      () => (this.completed = true)
    );

  }

  send() {
    // const msg = {
    //   msg: this.message,                                                    // 消息内容
    //   // type: this.type === SEND_TYPE.ALL ? SEND_TYPE.ALL : SEND_TYPE.SINGLE, // 类型
    //   // to: this.type === SEND_TYPE.SINGLE ? this.sendToUser : undefined            // 要发送的对象
    // };
    this.webSocketService.sendMessage(this.message);
  }

  play(){
    this.wavesurfer.playPause();
  }
}
